package com.maoye.ossp.biz.contract.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter;
import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.hotent.base.core.util.string.StringUtil;
import com.hotent.base.db.model.DefaultQueryFilter;
import com.maoye.ossp.biz.brand.entity.BrandCate;
import com.maoye.ossp.biz.brand.entity.SupplierRegister;
import com.maoye.ossp.biz.brand.service.IBrandCateService;
import com.maoye.ossp.biz.brand.service.IBrandReviewService;
import com.maoye.ossp.biz.brand.service.ISupplierRegisterService;
import com.maoye.ossp.biz.contract.entity.AdvertAssbrands;
import com.maoye.ossp.biz.contract.entity.AdvertAssociated;
import com.maoye.ossp.biz.contract.entity.AssociatedContract;
import com.maoye.ossp.biz.contract.entity.LeaseAssociated;
import com.maoye.ossp.biz.contract.entity.MarketAssociated;
import com.maoye.ossp.biz.contract.entity.ResultSapVo;
import com.maoye.ossp.biz.contract.entity.SelfAssociated;
import com.maoye.ossp.biz.contract.service.IAdvertAssociatedService;
import com.maoye.ossp.biz.contract.service.IContractService;
import com.maoye.ossp.biz.contract.service.ILeaseAssContractService;
import com.maoye.ossp.biz.contract.service.IMarketAssociatedService;
import com.maoye.ossp.biz.contract.service.ISelfAssociatedService;
import com.maoye.ossp.biz.contract.utils.ContractUtils;
import com.maoye.ossp.biz.contract.utils.JacksonUtils;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.service.IDataBean;
import com.maoye.ossp.common.util.ApplicationContextUtils;
import com.maoye.ossp.common.util.RequestContext;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.base.entity.BerthMaindata;
import com.maoye.ossp.sys.base.entity.CMCate;
import com.maoye.ossp.sys.base.entity.COMMCate;
import com.maoye.ossp.sys.base.entity.SysBaseFloor;
import com.maoye.ossp.sys.base.entity.SysBaseFormat;
import com.maoye.ossp.sys.base.entity.SysBaseShop;
import com.maoye.ossp.sys.base.entity.SysBaseShopFormat;
import com.maoye.ossp.sys.base.entity.SysBaseTaxRate;
import com.maoye.ossp.sys.base.entity.SysBasevipPolicy;
import com.maoye.ossp.sys.base.service.BerthMaindataService;
import com.maoye.ossp.sys.base.service.ICMCateService;
import com.maoye.ossp.sys.base.service.ICOMMCateService;
import com.maoye.ossp.sys.base.service.SysBaseFloorService;
import com.maoye.ossp.sys.base.service.SysBaseFormatService;
import com.maoye.ossp.sys.base.service.SysBaseShopFormatService;
import com.maoye.ossp.sys.base.service.SysBaseShopService;
import com.maoye.ossp.sys.base.service.SysBaseTaxRateService;
import com.maoye.ossp.sys.base.service.SysBasevipPolicyService;

@Controller
@RequestMapping(value = "biz/contract/commonContract/")
public class CommonContractController extends BaseController{
	@Resource
	private IAdvertAssociatedService  advertAssociatedService; //广告
	@Resource
	ILeaseAssContractService leassContractService;            //租赁
	
	@Resource
	private ISelfAssociatedService selfAssociatedService;    //自营
	
	@Resource
	private IMarketAssociatedService  marketAssociatedService;  //促销
	
	@Resource
	private IContractService  contractServce;                //联营
	
	@Resource
	ISupplierRegisterService supplierRegisterService;
	@Resource
	SysBaseTaxRateService sysBaseTaxRateService;
	@Resource
	private IBrandCateService brandCateService;		//品牌信息
	@Resource
	private ICMCateService icmCateService;		//招商分类
	@Resource
	ICOMMCateService iconcateService;  //   商品分类
	@Resource
	SysBasevipPolicyService vipService;
	@Resource
	private SysBaseShopService sysBaseShopService;
	@Resource
	BerthMaindataService brtThservice;
	@Resource
	SysBaseFormatService sysBaseFormatService ;
	@Resource
	private SysBaseShopFormatService sysBaseShopFormatService;
	@Resource
	SysBaseFloorService sysBaseFloorService;
	
	/**
	 * 取得供应商税票类型
	 * @param id
	 * @param request
	 * @param response
	 * @param model
	 * @throws IOException
	 * @author yangh
	 * @data 2014年5月1日
	 */
	@Resource IBrandReviewService brandReviewService;
	
	@RequestMapping(value ="{id}/getSupplierRegister")
	public void getSupplierRegister(@PathVariable  Long id,HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		SupplierRegister supplierRegister = supplierRegisterService.getBySupplierAccountId(id);
		StringBuilder jsonStr = new StringBuilder();
		jsonStr.append("{\"taxType\":");
		jsonStr.append(supplierRegister.getTaxType());
		jsonStr.append("}");
		out.print(jsonStr.toString());
		out.flush();
		out.close();
	}
	@SuppressWarnings("unused")
	@RequestMapping(value ="{taxType}/getTaxRateTypeCode")
	public void getTaxRateTypeCode(@PathVariable  String taxType,HttpServletRequest request,HttpServletResponse response,Model model) throws IOException{
		response.setCharacterEncoding("utf-8");
		String contextPath=request.getContextPath();
		PrintWriter out = response.getWriter();
		StringBuilder jsonStr = new StringBuilder();
		List<SysBaseTaxRate> taxRateList = sysBaseTaxRateService.getTaxRateList(taxType);
		jsonStr.append("[");

		for(int i = 0 ;i<taxRateList.size();i++){
			SysBaseTaxRate taxRate = taxRateList.get(i);
			jsonStr.append("{\"taxRateNum\":\"");
			jsonStr.append(taxRate.getTaxRateNum().toString());
			jsonStr.append("\",\"taxRate\":\"");
			jsonStr.append(taxRate.getTaxRate().toString());
			jsonStr.append("\"}");
			if(i<taxRateList.size()-1){
				jsonStr.append(",");
			}
		}    
		jsonStr.append("]");
		out.print(jsonStr.toString());
		out.flush();
		out.close();
	}
	
	
	/**
	 * 根据供应商编号获得品牌
	 * @param supplierNo
	 * @param request
	 * @param response
	 * @param model
	 * @author liuw
	 */
	@RequestMapping(value = "{supplierNo}/getBrandInfo")
	public void getBrandInfo(@PathVariable String supplierNo, HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception{
		List<BrandCate> brandCateList=brandCateService.getBySupplierNo(supplierNo);
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String str = "";
		str += "[";
		str +="{\"id\":\"\",\"name\":\"------请选择-----\"},";
		CMCate cmcCate =null;
		String name = "";
		for (int j = 0; j < brandCateList.size(); j++) {
			BrandCate cate = brandCateList.get(j);
			if(cate != null){ 
				cmcCate = icmCateService.getByCateNo(cate.getCateNo());  	  //招商分类
				if(cmcCate != null &&cmcCate.getCateName()!=null){
					name = cmcCate.getCateName() + " - ";
				}
			}
			name += cate.getBrandCname();;
			str += "{\"id\":\""+cate.getId()+"\", \"name\":\""+ name +"\"}";
			if(j != brandCateList.size()-1){
				str += ",";
			}
		}
		str += "]";
		out.write(str);
		out.flush();
		out.close();
	}
	/**
	 * 更新合同撤柜日期
	 * @return
	 * @author yangh
	 * @data 2014年5月14日
	 */
	@RequestMapping(value="{id}/updateTerminateDate")
	public String updateTerminateDate(@PathVariable Long id,Model model,HttpServletRequest request){
		model.addAttribute("id", id);
		return resultPage("/biz/contract/common/modalTerminateDate", model, request);
	}
	
	@RequestMapping(value = "queryBrandInfo")
	@ResponseBody
	public Map<String,Object> queryBrandInfo(Long id, String shopId,Model model) throws Exception
	{
		Map<String,Object> map = new HashMap<String, Object>();
		BrandCate cate = brandCateService.get(id);
		DefaultQueryFilter filter = new DefaultQueryFilter();
		filter.addFilter("brandCateId", id, QueryOP.EQUAL);
		String brandInviteHead=brandReviewService.getByBrandNo(cate.getBrandNo());
		
		CMCate cmcCate = null;
		String brandName = "";
		String cateName = "";
		if(!StringUtil.isEmpty(cate.getCateNo())){
			if(cate != null){ cmcCate = icmCateService.getByCateNo(cate.getCateNo());  cateName = cmcCate.getCateName();}     //招商分类
			brandName = cmcCate.getCateName()+" - "+cate.getBrand().getBrandCname();
			String cateNames = CommonContractController.getCateName(cmcCate, icmCateService);	//获得招商分类名称 
			cmcCate.setCateName(cateNames);
			
			List<COMMCate> commcate =iconcateService.getByCMCateId(cmcCate.getCateNo());  //商品分类
			
			
			//-------------------根据招商类查会员卡折率-----------------------------------
			Map<String, Object> map2 = new HashMap<String, Object>();
			if(commcate !=null&&!commcate.isEmpty()){
				map2.put("no", shopId);
				SysBaseShop shop = sysBaseShopService.getByNo(map2);
				map2.put("ruleId", commcate.get(0).getCateNo());
				map2.put("shopId", shop.getIntro());
				List<SysBasevipPolicy> polictListt =vipService.getList(map2);
				
				for (SysBasevipPolicy policyType : polictListt) {
					if("01".equals(policyType.getVipType())){
						map.put("ocardDiscount", policyType.getDiscount());
					}else if("02".equals(policyType.getVipType())){
						map.put("gcardDiscount", policyType.getDiscount());
					}
				}
			}
		}
		map.put("levelId", cate.getLevelId().toString());		//品牌等级
		map.put("brandId", cate.getId().toString());//品牌ID
		map.put("brandNo", cate.getBrandNo());//品牌编码
		map.put("brandCName", brandName);//品牌中文名 
		map.put("brandEName", cate.getBrand().getBrandEname());//品牌英文名
		map.put("cmcCateId", cmcCate.getCateNo());	//招商分类
		map.put("cmcCateName", cmcCate.getCateName());	//招商分类
		map.put("cateName", cateName);
		if(StringUtil.isNotEmpty(brandInviteHead)){
			map.put("brandInviteHead", brandInviteHead);
		}
		return map;
	}
	

	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "{storeId}/getFormat")
	public void getFormat(@PathVariable String storeId,HttpServletRequest request,HttpServletResponse response,Model model) throws Exception{
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		StringBuilder json = new StringBuilder();
		Map map = new HashMap();
		map.put("no", storeId);
		SysBaseShop shop = sysBaseShopService.getByNo(map);
		List<SysBaseShopFormat> sysBaseFormatList = sysBaseShopFormatService.getShopCodeCode(storeId);
		json.append("{");
		json.append("\"code\":\"");
		json.append(shop.getCompanyCode()+"\",");
		json.append("\"name\":\"");
		json.append(shop.getCompanyName()+"\",\"formatList\":");
		json.append("[");
		for (int i =0; i< sysBaseFormatList.size();i++) {
			SysBaseShopFormat sysBaseShopFormat = sysBaseFormatList.get(i);
			String formatCode = sysBaseShopFormat.getFormatCode();
			SysBaseFormat format = sysBaseFormatService.getFormatByCode(formatCode);
			json.append("{\"code\":\"");
			json.append(sysBaseShopFormat.getFormatCode()+"\",");
			json.append("\"name\":\"");
			String name = format.getName();
			json.append(name+"\"}");
			if(i<sysBaseFormatList.size()-1){
				json.append(",");
			}
			
		}
		json.append("]");
		json.append("}");
		out.write(json.toString());
		out.flush();
		out.close();
	}
	
	@RequestMapping(value="showModal")
	public String showModal(BerthMaindata berthMaindata, Model model,HttpServletRequest request){
		QueryFilter queryFilter = getQuerFilter(request,berthMaindata);
		queryFilter.addFilter("floor", berthMaindata.getFloor(), QueryOP.EQUAL);
		queryFilter.addFilter("siteid", berthMaindata.getSiteid(), QueryOP.EQUAL);
		if(StringUtil.isNotEmpty(berthMaindata.getMechId())){
			queryFilter.addFilter("mechId", berthMaindata.getMechId(), QueryOP.LIKE);
		}
		if(StringUtil.isNotEmpty(berthMaindata.getBerthId())){
			queryFilter.addFilter("berthId", berthMaindata.getBerthId(), QueryOP.LIKE);
		}
		Page<BerthMaindata> page = (Page<BerthMaindata>) brtThservice.find(queryFilter);
		if(page !=null){
			int totalSize = (page.getTotal() + page.getPageSize() - 1) / page.getPageSize();
			model.addAttribute("totalSize", totalSize);
		}
		model.addAttribute("page", page);
		return "/biz/contract/common/modalBerth";
	}
	/**
	 * 分页
	 * @param berthMaindata
	 * @param model
	 * @param request
	 * @param response
	 * @throws Exception
	 * @author yangh
	 * @data 2014年5月8日
	 */
	@RequestMapping(value="showModalPage")
	public void showModalPage(BerthMaindata berthMaindata, Model model,HttpServletRequest request, HttpServletResponse response) throws Exception{
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		QueryFilter queryFilter = getQuerFilter(request,berthMaindata);
		queryFilter.addFilter("floor", berthMaindata.getFloor(), QueryOP.EQUAL);
		queryFilter.addFilter("siteid", berthMaindata.getSiteid(), QueryOP.EQUAL);
		if(StringUtil.isNotEmpty(berthMaindata.getMechId())){
			queryFilter.addFilter("mechId", berthMaindata.getMechId(), QueryOP.LIKE);
		}
		if(StringUtil.isNotEmpty(berthMaindata.getBerthId())){
			queryFilter.addFilter("berthId", berthMaindata.getBerthId(), QueryOP.LIKE);
		}
		Page<BerthMaindata> page = (Page<BerthMaindata>) brtThservice.find(queryFilter);
		List<BerthMaindata> list = page.getList();
		StringBuffer sb = new StringBuffer(); 
		sb.append("{\"total\":\""+page.getTotal()+"\",");
		sb.append("\"pageNo\":\""+page.getPageNo()+"\",");
		sb.append("\"pageSize\":\""+page.getPageSize()+"\",");
		sb.append("\"jsonRoot\":[");
		for(int i = 0;i<list.size();i++){
			BerthMaindata berth = list.get(i);
			String berthId = berth.getBerthId();
			if(berthId ==null){
				berthId = "";
			}
			sb.append("{\"id\":\""+ berth.getId()).append("\",").append("\"floor\":\""+ berth.getFloor()).append("\",");
            sb.append("\"siteid\":\""+ berth.getSiteid()).append("\",").append("\"mechId\":\""+ berth.getMechId());  
            sb.append("\",").append("\"berthId\":\""+ berthId).append("\",");
            sb.append("\"area\":\""+ berth.getArea()).append("\",");  
            sb.append("\"adLength\":\""+ berth.getAdLength()).append("\",");  
            sb.append("\"adWeight\":\""+ berth.getAdWeight()).append("\",");  
            sb.append("\"adStandardvalue\":\""+ berth.getAdStandardvalue()).append("\"");  
            sb.append("},");
		}
		if(list.size()>0){
			sb.deleteCharAt(sb.lastIndexOf(","));
		}
		  // 删去最后一个逗号  
        sb.append("]}"); 
        out.print(sb);
        out.flush();
		out.close();
	}
	
	/**
	 * 合同同步SAP
	* @Title: sendToSap
	* @Description: TODO(这里用一句话描述这个方法的作用)
	* @param @param id
	* @param @param request
	* @param @param response
	* @param @param model
	* @param @param redirectAttributes
	* @param @return
	* @param @throws Exception    设定文件
	* @return List<Object>    返回类型
	* @throws
	 */
	@ResponseBody
	@RequestMapping(value = "{id}/sendToSap")
	public List<Object> sendToSap(@PathVariable String id,HttpServletRequest request, HttpServletResponse response,Model model,RedirectAttributes redirectAttributes) throws Exception{
		request.setAttribute("id", id);
		StringBuffer sb = new StringBuffer();
		String s_bean =request.getParameter("s_bean");
		String contractNo = request.getParameter("contractId");
		response.setContentType("application/json; charset=UTF-8");
		IDataBean dataBean = (IDataBean) ApplicationContextUtils.getBean(s_bean);
		RequestContext requestContext = new RequestContext(request);
		List<Object> dataList = dataBean.getDataList(requestContext);
		List<Object> messageList =Lists.newArrayList();
		for (Object object : dataList) {
			ResultSapVo vo =(ResultSapVo)object;
			HashMap<String, Object> map = Maps.newHashMap();
			map.put("id", id);
			map.put("operateState", vo.getStatus());
			sb.append(vo.getMenssage());
			if(vo.getContractType() !=null){
				if(vo.getContractType().equals(ContractUtils.CONTRACT_TYPE_LY)){
					AssociatedContract contract=contractServce.get(id);
					if(!ContractUtils.CONTRACT_STATE_SUBMIT_SAP_S.equals(contract.getOperateState())){
						contractServce.updSapStatus(map);
					}
				}else if(vo.getContractType().equals(ContractUtils.CONTRACT_TYPE_ZY_DX)){
					SelfAssociated contract=selfAssociatedService.get(id);
					if(!ContractUtils.CONTRACT_STATE_SUBMIT_SAP_S.equals(contract.getOperateState())){
						selfAssociatedService.updSapStatus(map);
					}
				}else if(vo.getContractType().equals(ContractUtils.CONTRACT_TYPE_ZP)){
					LeaseAssociated contract=leassContractService.get(id);
					if(!ContractUtils.CONTRACT_STATE_SUBMIT_SAP_S.equals(contract.getOperateState())){
						leassContractService.updSapStatus(map);
					}
				}else if(vo.getContractType().equals(ContractUtils.CONTRACT_TYPE_GG)){
					AdvertAssociated contract=advertAssociatedService.get(id);
					if(!ContractUtils.CONTRACT_STATE_SUBMIT_SAP_S.equals(contract.getOperateState())){
						advertAssociatedService.updSapStatus(map);
					}
				}else if(vo.getContractType().equals(ContractUtils.CONTRACT_TYPE_CX)){
					MarketAssociated contract=marketAssociatedService.get(id);
					if(!ContractUtils.CONTRACT_STATE_SUBMIT_SAP_S.equals(contract.getOperateState())){
						marketAssociatedService.updSapStatus(map);
					}
				}
			}
		}
		messageList.add(sb);
		return messageList ;
	}
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "getLoadFormat")
	public void getLoadFormat(HttpServletRequest request,HttpServletResponse response,Model model,String storeId) throws Exception{
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		StringBuilder json = new StringBuilder();
		Map map = new HashMap();
		map.put("no", storeId);
		List<SysBaseShopFormat> sysBaseFormatList = sysBaseShopFormatService.getShopCodeCode(storeId);
		json.append("[");
		for (int i =0; i< sysBaseFormatList.size();i++) {
			SysBaseShopFormat sysBaseShopFormat = sysBaseFormatList.get(i);
			String formatCode = sysBaseShopFormat.getFormatCode();
			SysBaseFormat format = sysBaseFormatService.getFormatByCode(formatCode);
			json.append("{\"code\":\"");
			json.append(sysBaseShopFormat.getFormatCode()+"\",");
			json.append("\"name\":\"");
			String name = format.getName();
			json.append(name+"\"}");
			if(i<sysBaseFormatList.size()-1){
				json.append(",");
			}
		}
		json.append("]");
		out.write(json.toString());
		out.flush();
		out.close();
	}

	/**
	 * 根据地区取得门店
	 * 
	 * @author yangh
	 * @throws IOException 
	 * @data 2014年4月29日
	 */
	@RequestMapping(value="{areaId}/getStoreByAreaId")
	public void getStoreByAreaId(@PathVariable String areaId,Model model,HttpServletRequest request,HttpServletResponse response) throws IOException{
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		StringBuilder json = new StringBuilder();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pid",areaId);
		List<SysBaseShop> shopList = sysBaseShopService.getShopsByPId(map);
		json.append("[");
		for(int i=0;i<shopList.size();i++){
			SysBaseShop shop = shopList.get(i);
			json.append("{\"code\":\"");
			json.append(shop.getNo()+"\",");
			json.append("\"name\":\"");
			json.append(shop.getName()+"\"}");
			if(i<shopList.size()-1){
				json.append(",");
			}
		}
		json.append("]");
		out.write(json.toString());
		out.flush();
		out.close();
	}
	/**
	 * 根据门店选取楼层
	 * @param floorId
	 * @param model
	 * @param request
	 * @param response
	 * @throws IOException
	 * @author yangh
	 * @data 2014年4月29日
	 */
	@RequestMapping(value="{floorId}/getFloorByStoreId")
	public void getFloorByStoreId(@PathVariable String floorId,Model model,HttpServletRequest request,HttpServletResponse response) throws IOException{
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		StringBuilder json = new StringBuilder();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pid",floorId);
		List<SysBaseFloor> floorList = sysBaseFloorService.getFloorByPId(map);
		json.append("[");
		for(int i=0;i<floorList.size();i++){
			SysBaseFloor floor =  floorList.get(i);
			json.append("{\"code\":\"");
			json.append(floor.getCode()+"\",");
			json.append("\"name\":\"");
			json.append(floor.getName()+"\"}");
			if(i<floorList.size()-1){
				json.append(",");
			}
		}
		json.append("]");
		out.write(json.toString());
		out.flush();
		out.close();
	}
	
	@RequestMapping(value = "editAssbrand")
	public String editAssbrand(Model model,RedirectAttributes redirectAttributes, HttpServletRequest request,
			HttpServletResponse response,String assBrand,String operate,String num, String supplierNo, String brandId, String iszs) throws Exception {
		String _brand=assBrand.replace("'", "\"");
		SimpleFilterProvider fp = new SimpleFilterProvider();
		fp.addFilter(
				"executeFilter",
				SimpleBeanPropertyFilter.serializeAllExcept(new String[] {
				 "createBy" }));
		AdvertAssbrands brand =JacksonUtils.create().filter("myFilter", "id").json2Obj(_brand, AdvertAssbrands[].class)[0];
		model.addAttribute("brand", brand);
		CMCate cmcCate = null;
		CMCate cmcCate2 = null;
		String cateName = "";
		if(brand.getInviteCate()!=null){
			cmcCate = icmCateService.getByCateNo(brand.getInviteCate());
			cateName = cmcCate.getCateName();
			String cateNames = CommonContractController.getCateName(cmcCate, icmCateService);	//获得招商分类名称 
			cmcCate.setCateName(cateNames);
		}
		if(brand.getPurchasingGroup()!=null){
			cmcCate2= icmCateService.getByCateNo(brand.getPurchasingGroup());
		}
		model.addAttribute("cmcCate", cmcCate);
		model.addAttribute("purchasingGroup", cmcCate2);
		model.addAttribute("operate","edit");
		model.addAttribute("num",num);
		model.addAttribute("cateName", cateName);
		model.addAttribute("supplierNo", supplierNo);
		model.addAttribute("brandId", brandId);
		model.addAttribute("iszs", iszs);
		return "/biz/contract/common/modalBarnd";
	}
	
	
	/**
	 * 获得招商分类父级名称
	 * @author liuwei
	 */
	public static String getCateName(CMCate cmcCate, ICMCateService icmCateService) throws Exception{
		String cateName ="";
		if(cmcCate.getParent() != null){			
			if(cmcCate.getParent().getParentId()!=null&&cmcCate.getParent().getParentId()!=0){		
				CMCate cate2 = cmcCate.getParent().getParent();
				cateName += cate2.getCateName()+" - ";			//大类名称
			}
			cateName += cmcCate.getParent().getCateName()+" - ";		//中类名称
		}
		cateName += cmcCate.getCateName();		//小类名称
		return cateName;
	}
	
	@RequestMapping(value = "addAssbrands")
	public String addAssbrands(String supplierNo, Model model) {
		model.addAttribute("operate","add");
		model.addAttribute("supplierNo", supplierNo);
		return "/biz/contract/common/modalBarnd";
	}

}